/*
 * @Description: config读取模块
 * @Author: BiChunkai 321521004@qq.com
 * @Date: 2025-06-03 13:33:05
 * @FilePath: /armEyeCalib_cpp/configDemo/configread.cpp
 *
 * Copyright (c) 2025 by 无锡捷普迅科技有限公司, All Rights Reserved.
 */
#include "configread.h"

ConfigRead::ConfigRead()
{

}

void ConfigRead::load(const std::string& filename)
{
    std::ifstream file(filename);
    std::string line, section;

    while(std::getline(file, line))
    {
        if(line.empty() || line[0] == ';') continue;

        if(line[0] == '[' && line[line.size() - 1] == ']')
        {
            section = line.substr(1, line.size() -2);
        }
        else
        {
            size_t pos = line.find('=');
            if(pos != std::string::npos){
                std::string key = line.substr(0, pos);
                std::string value = line.substr(pos+1);
                configData[section][key] = value;
            }
        }
    }
}

std::string ConfigRead::get(const std::string& section, const std::string& key)
{
    return configData[section][key];
}
